/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package MathCore.Renders;

import MathCore.Expression;
import MathCore.Render;
import javax.microedition.lcdui.Graphics;

/**
 *
 * @author Александр
 */
public class StringRender extends Block
{
	String string;

	public StringRender(String string)
	{
		this.string = string;
		width = Render.getFont().stringWidth(string);
		height = Render.getFont().getHeight();
		center = height/2;
	}


	public int width()
	{
		return width;
	}

	public int height()
	{
		return height;
	}

	public int center()
	{
		return center;
	}

	public void draw(Graphics g, int x, int y, int style)
	{
		saveCoordinates(x, y, style);

		// смещаем координаты, учитывая стили (сводим к LEFT|TOP)
		if(style(style, Block.BOTTOM))	y -= height();
		if(style(style, Block.RIGHT))	x -= width();
		if(style(style, Block.HCENTER))	x -= width()/2;
		if(style(style, Block.VCENTER)) y -= height() - center();

		// рисуем
		if(g == null) return;
		g.setColor(Render.textColor);
		g.drawString(string, x, y, Graphics.LEFT|Graphics.TOP);
	}

	public void extract(Expression exp)
	{
	}

	public void parse()
	{
	}

}
